﻿<%@ Page Language="C#" MasterPageFile="~/SecondPage.master" AutoEventWireup="true" CodeFile="Search.aspx.cs" Inherits="Search" Title="Search" %>


<%@ Register TagPrefix="uc1" TagName="AdvancedSearch" Src="Controls/AdvancedSearch.ascx" %>
<%@ Register TagPrefix="uc1" TagName="CategoryDropDown" Src="Controls/CategoryDropDown.ascx" %>
<%@ Register TagPrefix="uc1" TagName="CategoryPath" Src="Controls/CategoryPath.ascx" %>
<%@ Register TagPrefix="uc1" TagName="CategoryBrowse" Src="Controls/CategoryBrowse.ascx" %>
<%@ Register TagPrefix="uc1" TagName="FeaturedAd" Src="Controls/FeaturedAd.ascx" %>
<%@ Import Namespace="AspNet.StarterKits.Classifieds.Web" %>
<%@ Register Src="Controls/CategorybyTreeView.ascx" TagName="CategorybyTreeView"
    TagPrefix="uc2" %>
<asp:Content ID="SecondBarContent" ContentPlaceHolderID="SecondBar" runat="server">
    <div id="crumbs_text" style="display: none">
        <uc1:CategoryPath ID="CategoryPath" runat="server" OnCategorySelectionChanged="CategoryPath_CategorySelectionChanged" />
    </div>
</asp:Content>
<asp:Content ID="MainContent" ContentPlaceHolderID="Main" runat="server">
    <div class="navigate">
        <p>
            <asp:Label ID="NormalSearchLabel" runat="server" CssClass="normal_weight"></asp:Label>
            <asp:Label ID="NormalSearchCriteria" runat="server"></asp:Label>
        </p>
    </div>
    <div class="cols">
        <div class="left float-left">
            <uc2:CategorybyTreeView ID="CategorybyTreeView1" runat="server" OnCategorySelectionChanged="CategorybyTreeView1_CategorySelectionChanged"  />
        </div>
        <div class="right float-right">
            <div class="header">
                <span>Showing <asp:Label ID="lblLow" runat="server" Text="Label"></asp:Label>
                    - 
                    <asp:Label ID="lblHigh" runat="server" Text="Label"></asp:Label>                    
                    of
                    <asp:Label ID="lblTotal" runat="server" Text="Label"></asp:Label>
                    ads</span>
                <div class="filter float-right">
                    <input type="checkbox" name='xx' id='xx' class="checbox" />
                    <label for="xx" class="label">
                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                        Gallery view
                    </label>
                    <select name='select' class="select">
                        <option>Most recent</option>
                    </select>
                </div>
                <div class="clear">
                </div>
            </div>
            <div class="body">
                <div id="search_n_browse" style="display: none">
                    <div id="search">
                        <asp:Panel ID="SearchPanel" runat="server" DefaultButton="SearchButton">
                            <fieldset>
                                <legend>Search</legend>
                                <asp:TextBox ID="SearchTermTextBox" runat="server" CssClass="search_box" />
                                <uc1:CategoryDropDown ID="CategoryDropDown" runat="server" SelectOptionVisible="false"
                                    OnCategorySelectionChanged="CategoryDropDown_CategorySelectionChanged" />
                                <asp:Button ID="SearchButton" runat="server" Text="Search" OnClick="SearchButton_Click" />
                                <asp:HyperLink ID="AdvancedSearchLink" runat="server" NavigateUrl="~/AdvancedSearch.aspx">[go to advanced search]</asp:HyperLink>
                            </fieldset>
                        </asp:Panel>
                    </div>
                    <div id="browse">
                        <fieldset>
                            <legend>Continue Browsing Subcategories</legend>
                            <asp:ListBox ID="SubcategoriesList" runat="server" Rows="6" DataSourceID="CategoryDataSource"
                                DataTextField="NameWithActiveCount" DataValueField="IdString" AutoPostBack="True"
                                OnDataBound="SubcategoriesList_DataBound" OnSelectedIndexChanged="SubcategoriesList_SelectedIndexChanged">
                            </asp:ListBox>
                        </fieldset>
                    </div>
                </div>
                <div id="content_header" class="hidden">
                    <a id="content_start"></a>
                    <asp:PlaceHolder ID="SearchingByAdvancedPanel" runat="server" Visible="false">
                        <h2>
                            Advanced Search Criteria</h2>
                        <br />
                        <br />
                        <asp:Label ID="AdvancedSearchCriteria" runat="server"></asp:Label>
                        <br />
                        <asp:LinkButton ID="RemoveAdvancedSearch" runat="server" Text="[remove advanced criteria]"
                            OnClick="RemoveAdvancedSearch_Click"></asp:LinkButton>
                    </asp:PlaceHolder>
                    <asp:PlaceHolder ID="NormalSearch" runat="server" Visible="false">
                        <%--<asp:Label ID="NormalSearchLabel" runat="server" CssClass="normal_weight"></asp:Label>--%>
                        <br />
                        <%-- <asp:Label ID="NormalSearchCriteria" runat="server"></asp:Label>--%>
                        <br />
                        <asp:LinkButton ID="ClearSearch" runat="server" Text="[clear search]" OnClick="ClearSearch_Click"></asp:LinkButton>
                    </asp:PlaceHolder>
                </div>
                <div id="content">
                    <asp:Panel ID="ResultsPanel" runat="server">
                        <asp:Repeater ID="adsRepeater" runat="server" DataSourceID="AdSearchDataSource" OnItemDataBound="adsRepeater_ItemDataBound">
                            <ItemTemplate>
                                <div class="item float-left">
                                    <a href='<%#String.Format("ShowAd.aspx?id={0}", Eval("id")) %>' rel='<%#String.Format("ajaxTooltip.aspx?q={0}", Eval("id")) %>' class="hastip" title='<%#Eval("Title") %>'>
                                    <asp:Image AlternateText="Ad Preview photo" ImageUrl='<%#String.Format("~/PhotoDisplay.ashx?photoid={0}&amp;size=medium", Eval("PreviewImageId")) %>'
                                        ID="image" runat="server"  />
                                        </a>
                                    <h3>
                                        <%#String.Format("&#163;{0:#,###,###.00}", Eval("Price")) %>
                                    </h3>
                                    <p>
                                        <asp:HiddenField ID="idHidden" runat="server" Value='<%#Eval("Id") %>' />
                                        <asp:HyperLink runat="server" ID="link" CssClass="hastip" ToolTip='<%#Eval("Title") %>'
                                            NavigateUrl='<%#String.Format("~/ShowAd.aspx?id={0}", Eval("id")) %>'><%#Eval("Title").ToString().Substring(0, Eval("Title").ToString().Length > 45 ? 45 : Eval("Title").ToString().Length)%>...</asp:HyperLink>
                                    </p>
                                    <span class="location">
                                        <%# OutputFormatting.AdTypeToString(Eval("AdType")) %></span><br />
                                    <span class="time">Posted:
                                        <%#String.Format("{0:dd/MM/yy}", Eval("DateCreated")) %></span>
                                </div>
                            </ItemTemplate>
                            <FooterTemplate>
                                <div class="clear">
                                </div>
                            </FooterTemplate>
                        </asp:Repeater>
                        <div class="pagination">
                            <asp:Label ID="noItem" runat="server" Text="No ads found"></asp:Label>
                            <asp:Repeater ID="rePagination" runat="server" OnItemCommand="rePagination_ItemCommand"
                                OnItemDataBound="rePagination_ItemDataBound">
                                <HeaderTemplate>
                                    <img src="app_themes/default/images/p_left_bullet.png" />
                                    <asp:LinkButton ID="lnkPrev" runat="server" CommandArgument="1" CommandName="selectPage">Prev</asp:LinkButton>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkItem" runat="server" CommandArgument='<%#Eval("page") %>'
                                        CommandName="selectPage"><%#Eval("page") %></asp:LinkButton>
                                </ItemTemplate>
                                <FooterTemplate>
                                    <asp:LinkButton ID="lnkNext" CommandName="selectPage" runat="server">Next</asp:LinkButton>
                                    <img src="app_themes/default/images/p_right_bullet.png" />
                                </FooterTemplate>
                            </asp:Repeater>
                        </div>
                    </asp:Panel>
                    <asp:Panel ID="BrowsePanel" runat="server" Visible="False">
                        <asp:PlaceHolder ID="Hide" runat="Server" Visible="True">
                            <div class="display_left">
                                <uc1:FeaturedAd ID="FeaturedAd" runat="server" />
                            </div>
                            <div class="display_right">
                                <uc1:CategoryBrowse ID="CategoryBrowser" runat="server" OnCategorySelectionChanged="CategoryBrowse_CategorySelectionChanged">
                                </uc1:CategoryBrowse>
                            </div>
                        </asp:PlaceHolder>
                    </asp:Panel>
                </div>
            </div>
        </div>
        <div class="clear">
        </div>
    </div>
    <!-- uc1:AdvancedSearch (invisible) is used to handle parameters for AdSearchDataSource -->
    <uc1:AdvancedSearch ID="AdvancedSearch" runat="server" Visible="false"></uc1:AdvancedSearch>
    <asp:ObjectDataSource ID="AdSearchDataSource" runat="server" TypeName="AspNet.StarterKits.Classifieds.BusinessLogicLayer.AdsDB"
        SelectMethod="GetActiveAdsByQueryWithPaging" OldValuesParameterFormatString="original_{0}"
        OnSelected="AdSearchDataSource_Selected">
        <SelectParameters>
            <asp:Parameter DefaultValue="20" Name="pageSize" Type="Int32" />
            <asp:ControlParameter ControlID="AdvancedSearch" DefaultValue="1" Name="currentPage"
                PropertyName="currentPage" Type="Int32" />
            <asp:ControlParameter Name="categoryId" DefaultValue="0" Type="Int32" ControlID="CategoryDropDown"
                PropertyName="CurrentCategoryId"></asp:ControlParameter>
            <asp:ControlParameter Name="memberId" ControlID="AdvancedSearch" PropertyName="MemberId"
                Type="Int32" DefaultValue="0" />
            <asp:ControlParameter Name="maxPrice" ControlID="AdvancedSearch" PropertyName="MaximumPrice"
                Type="Decimal" DefaultValue="-1" />
            <asp:ControlParameter Name="searchTerm" DefaultValue="" Type="String" ControlID="SearchTermTextBox"
                PropertyName="Text"></asp:ControlParameter>
            <asp:ControlParameter Name="location" ControlID="AdvancedSearch" PropertyName="Location"
                Type="String" DefaultValue="" />
            <asp:ControlParameter Name="adType" ControlID="AdvancedSearch" PropertyName="AdType"
                Type="Int32" DefaultValue="0" />
            <asp:Parameter Type="Int32" DefaultValue="0" Name="adLevel"></asp:Parameter>
            <asp:ControlParameter Name="dayRange" ControlID="AdvancedSearch" PropertyName="DayRange"
                Type="Int32" DefaultValue="-1" />
            <asp:ControlParameter Name="mustHaveImage" ControlID="AdvancedSearch" PropertyName="MustHavePhotos"
                Type="Boolean" DefaultValue="False" />  
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="CategoryDataSource" TypeName="AspNet.StarterKits.Classifieds.Web.CategoryCache"
        SelectMethod="GetBrowseCategoriesByParentId" runat="server">
        <SelectParameters>
            <asp:ControlParameter Name="parentCategoryId" DefaultValue="0" Type="Int32" ControlID="CategoryDropDown"
                PropertyName="CurrentCategoryId"></asp:ControlParameter>
        </SelectParameters>
    </asp:ObjectDataSource>

    <script>
        jQuery('document').ready(function(){
            jQuery('a.hastip').cluetip({ dropShadow: false, cluetipClass: 'jtip', showTitle: false, clickThrough: true });
        });
    </script>

</asp:Content>
